package com.uw.uwrpc.core.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;

import java.util.HashMap;
import java.util.Map;

@Data
@RefreshScope
@ConfigurationProperties("uw.rpc")
public class UWRpcProperty {

    private UWRpcAppProperty app;

    private UWRpcConsumerProperty consumer;

    private UWRpcProviderProperty provider;

    private UWRpcZkProperty zk;


    /**
     * 服务配置项
     */
    @Data
    public static class UWRpcAppProperty {
        private String appId = "demo";
        private String namespace = "default";
        private String env = "dev";
    }

    /**
     * 服务消费者配置项
     */
    @Data
    public static class UWRpcConsumerProperty {
        // 重试次数
        private Integer retryTime = 2;
        // 重试次数
        private Integer isolateThreshold = 3;
        // 灰度比率，0-100。表示灰度调用的占比。
        private Integer grayRatio = 0;

        //半开策略，初始化延迟时间，单位 ms
        private Integer halfOpenInitialDelay = 10_000;
        //半开策略，重试间隔时间，单位 ms
        private Integer halfOpenDelay = 30_000;

        // 超时时间，单位 ms
        private Integer readTimeout = 1000;
        private Integer writeTimeout = 1000;
        private Integer connectTimeout = 1000;
    }

    /**
     * 服务提供者配置项
     */
    @Data
    public static class UWRpcProviderProperty {
        // 流控 tps
        private Integer tpsLimit = 20;

        Map<String, String> metas = new HashMap<>();
    }

    /**
     * 注册中心配置项
     */
    @Data
    public static class UWRpcZkProperty {
        private String server = "localhost:2181";
        private String root = "uwrpc";
    }
}
